<?php
include "conn.php";
$data = $_REQUEST;

function updateBlog(): bool
{
    global $mysql;
    global $data;
    $title = mysqli_real_escape_string($mysql, $data['title']);
    $content = mysqli_real_escape_string($mysql, $data['content']);
    $author = mysqli_real_escape_string($mysql, $data['author']);
    $id = $data['id'];
    $res = mysqli_query($mysql, "UPDATE tb_blog SET title = '$title', content = '$content',author = '$author' WHERE id_blog = '$id';");
    if ($res !== true) {
        echo mysqli_error($mysql);
        return false;
    }
    return true;
}

?>

<!doctype html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>更新状态</title>
</head>
<body>
<?php
if (updateBlog()) {
    header('Refresh:2;url=manageBlog.php');
    echo '<h1>2秒后返回，更新成功</h1>';
} else {
    exit();
}
?>
</body>
</html>
